﻿using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SignalRApp
{
    internal class ChatHub : Hub
    {
        public async Task SendMessage(string user, string message)
        {

            ///这里面可以写任意逻辑处理
            await base.Clients.All.SendAsync("ReceiveMessage", user, message, "给所有人发");
        }
        /// <summary>		
        /// 重写集线器连接事件		
        /// </summary>		
        /// <returns></returns>		
        public override Task OnConnectedAsync()
        {
            Console.WriteLine($"{Context.ConnectionId}已连接");
            return base.OnConnectedAsync();
        }
        /// <summary>		
        /// 重写集线器关闭事件		
        /// </summary>		
        /// <param name="exception"></param>		
        /// <returns></returns>		
        public override Task OnDisconnectedAsync(Exception exception)
        {
            Console.WriteLine("触发了关闭事件");
            return base.OnDisconnectedAsync(exception);
        }
    }
}
